﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Manager.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>
<%@ Import Namespace="B2B.Models" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">

<h2>CreateProduct</h2>

</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="HEAD" runat="server">
</asp:Content>

<asp:Content ID="Content3" ContentPlaceHolderID="main_content" runat="server">
    <%
        ArrayList listDVT = (ArrayList)ViewData["donvitinh"];
        ArrayList listQG = (ArrayList)ViewData["quocgia"];
    %>
    <div>
        <form action="/Manage/AddProduct" method="post" enctype="multipart/form-data">
            <table border="1">
                <tr>
                    <th>Product Name:</th>
                    <td style="width:300px">
                        <input id="tenSP" name="tenSP" type="text" />
                        <div id="divCheckTenSanPham" style="color:red"></div>
                    </td>
                </tr>
                <tr>
                    <th>Image: </th>
                    <td>
                        <input name="fileUpload" type="file" />
                        <div id="divCheckFileUpload" style="color:red"></div>
                    </td>
                </tr>
                <tr>
                    <th>Price: </th>
                    <td>
                        <input style="width:80px" onkeypress="return onlyNumbers(event)"  type="text" />/
                        <select style="width:auto" name="maDVT">
                            <option value="0">--Please select unit--</option>
                            <%
                                foreach(var dvt in listDVT)
                                {
                            %>
                            <option value="<%=((DonViTinh)dvt).MaDVT %>">
                                <%=((DonViTinh)dvt).TenDVT %>
                            </option>
                            <%} %>
                        </select>
                        <div id="divCheckSelectDVT" style="color:red"></div>
                    </td>
                </tr>
                <tr>
                    <th>Min. Order: </th>
                    <td>
                        <input id="txtSoluongDatTT" type="text" onkeypress="return onlyNumbers(event)" name="soLuongDatToiThieu" />
                        <div id="divCheckSoLuongDatTT" style="color:red"></div>
                    </td>
                </tr>
                <tr>
                    <th>Kha nang cung ung: </th>
                    <td>
                        <input id="txtKhaNangCungUng" name="khaNangCungUng" onkeypress="return onlyNumbers(event)" type="text" />
                        <div id="divCheckKhaNangCungUng" style="color:red"></div>
                    </td>
                </tr>

                <tr>
                    <th>Payment Type:</th>
                    <td>
                        <div id="divPaymentType">
                            <input style="width:150px" name="loaiThanhToan" type="text" /><input  type="button" value="+" id="btnAddPaymentType" />
                            <div id="divCheckPaymentType" style="color:red"></div>
                        </div>
                    </td>
                </tr>
                <tr>
                    <th>Country: </th>
                    <td>
                        <select id="selectQG" name="maQuocGia">
                               <option value="0">--Please select country--</option>
                            <%
                                foreach(var qg in listQG)
                                {
                            %>
                            <option value="<%=((QuocGia)qg).MaQuocGia %>"><%=((QuocGia)qg).TenQuocGia %></option>                        
                            <%} %>
                        </select>
                        <div id="divSelectQuocGia" style="color:red"></div>
                    </td>
                </tr>
                <tr>
                
                       <th style="width: 280px; height: 62px;">Product Category: </th>
                            <!--Tu viet group box bang javascript de chon muc mua hang-->
                       <td style="width: 228px; height: 62px;">
                           <select ID="selProductCategory">
                                        <option value="0">--Please select category--</option>
                                        <%foreach(var lv in (ArrayList)ViewData["linhvuc"]) 
                                          {%>                             
                                            <option onclick="loadDanhMuc('<%=((LinhVuc)lv).MaLinhVuc.ToString() %>')" value="<%=((LinhVuc)lv).MaLinhVuc.ToString() %>"><%=((LinhVuc)lv).TenLinhVuc.ToString() %></option>
                                        <%}%>
                          </select>
                          <div id="divDanhMuc"></div>
                          <div id="divCheckCategory" style="color: red"></div>

                      </td>
                </tr>
                <tr>
                    <th>Chi tiet:</th>
                    <td>
                        <div id="divChiTietSP"></div>
                        <div id="divCheckChiTiet" style="color:red"></div>
                    </td>
                </tr>

                <tr>
                    <th>Chi tiet: </th>
                    <td>
                        <textarea id="txtChitiet" name="chiTiet"></textarea>
                    </td>
                </tr>
                <tr>
                    <td colspan="2"><input type="submit" value="Create" /></td>
                </tr>
            </table>
        </form>
    </div>
    
    <script type="text/ecmascript">
          function loadDanhMuc(maLinhVuc)
            {
                if (maLinhVuc != 0) {
                    $.getJSON("/Home/DanhSachDanhMuc?id=" + maLinhVuc,
                     function (data) {
                         document.getElementById("checkCategory").innerText = "";
                         var s = '';
                         s += "<select id='MaDanhMuc' name='maDanhMuc'>";
                         s += "<option value=0>--Please select ---</optinon>"
                         for (i = 0 ; i < data.length; i++) {
                             s += "<option onclick = 'loadThongTinSanPham(" + data[i].MaDanhMuc + ")' value='" + data[i].MaDanhMuc + "'>" + data[i].TenDanhMuc + "</option>";
                         }
                         s += "</select>";
                         $("#divDanhMuc").html(s);
                     });
                }
                else
                {
                    document.getElementById("checkCategory").innerText = "Please select a item in category";
                }
          }
        
          function loadThongTinSanPham(maDM) {
              if (maDM != -0) {
                  $.getJSON("/Manage/ListDetailProduct?madm=" + maDM,
                      function (data) {
                          var s = '';
                          s += '<table>';
                          for (i = 0; i < data.length; i++) {
                              s += '<tr>';
                             s += '<th>' + data[i].TenThongSo + ':</th>';
                             s += '<td> <input name="[' + i + '].Chitiet" type="text" /> <input name="[' + i + '].MaThongSo" type="hidden" value = "' + data[i].MaThongSo + '"/></td>';                              
                             s += '</tr>';
                          }
                          s += '</table>'
                          $("#divChiTietSP").html(s);
                      });
              }
          }

          function checkProductName() {
              var tensp = $("#tenSP").val();
              if (tensp.length == 0)
                  return false;
              return true;
          }

          function checkSelectProductCategory() {
              var i = $("#selProductCategory").val();
              if (i == 0)
                  return false;
              return true;
          }
            
          function checkSelectQG() {
              var i = $("#selectQG").val();
              if (i == 0)
                  return false;
              return true;
          }

          function checkMaDanhMuc() {
              var i = $("#MaDanhMuc").val();
              if (i == 0)
                  return false;
              return true;
          }

          function onlyNumbers(e) {
              var keyword = null;
              if (window.event) {
                  keyword = window.event.keyCode;
              } else {
                  keyword = e.which; //NON IE;
              }

              if (keyword < 48 || keyword > 57) {
                  if (keyword == 48 || keyword == 127 || keyword == 8) {
                      return;
                  }
                  $("#CheckQuantity").html("You have to enter number");
                  return false;
              }
              $("#CheckQuantity").html("");
          }
      </script>

</asp:Content>
